// pages/check/jishi/jishi.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: '',
		index: '',
		index1: '',
		list1: ['男', '女'],
		region: '',
		CardNoImg2: '',
		CardNoImg1: '',
		http: getApp().globalData.map,
		CardNoImg: '',
		uname: '',
		mobile: '',
		workYear: '',
		yyzz: '',
		zt:false,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
			}
		})
		wx.request({
			url: getApp().globalData.http + 'action=getMasterWorker',
			success: (e) => {
				let a = []
				console.log(this.data.index != "")
				e.data.data.forEach(function(item, index) {
					a.push(item.jslb)
				})
				console.log(e)
				this.setData({
					list: a
				})
			}
		})
	},
	bindPickerChange(e) {
		this.setData({
			index: e.detail.value
		})
	},
	bindPickerChange1(e) {
		this.setData({
			index1: e.detail.value
		})
	},
	bindRegionChange: function(e) {
		this.setData({
			region: e.detail.value
		})
	},
	sc(en) {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let c = JSON.parse(res.data)
						if (en.currentTarget.dataset.id == 0) {
							that.setData({
								CardNoImg: c.data.headImage
							})
						} else if (en.currentTarget.dataset.id == 1) {
							that.setData({
								CardNoImg1: c.data.headImage
							})
						} else if (en.currentTarget.dataset.id == 2) {
							that.setData({
								CardNoImg2: c.data.headImage
							})
						} else {
							that.setData({
								yyzz: c.data.headImage
							})
						}
					}
				});
			}
		})
	},
	dete(e) {
		if (e.currentTarget.dataset.id == 0) {
			this.setData({
				CardNoImg: ''
			})
		} else if (e.currentTarget.dataset.id == 1) {
			this.setData({
				CardNoImg1: ''
			})
		} else if (e.currentTarget.dataset.id == 2) {
			this.setData({
				CardNoImg2: ''
			})
		} else {
			this.setData({
				yyzz: ''
			})
		}
	},
	uname(e) {
		this.setData({
			uname: e.detail.value
		})
	},
	mobile(e) {
		this.setData({
			mobile: e.detail.value
		})
	},
	workYear(e) {
		this.setData({
			workYear: e.detail.value
		})
	},
	zt(e) {
		this.setData({
			zt: !(e.currentTarget.dataset.id)
		})
	},
	goin() {
		if (this.data.uname != '' && this.data.mobile != '' && this.data.index1 != '' && this.data.region[0] != '' && this.data
			.index != '' && this.data.workYear != '' && this.data.region != ''&& this.data.zt == true &&this.data.CardNoImg2!=''
			&&this.data.CardNoImg1!='' &&this.data.CardNoImg!='') {
			wx.request({
				url: getApp().globalData.http + 'action=workerApp&uid=' + this.data.uid + '&uname=' + this.data.uname +
					'&mobile=' +
					this.data.mobile + '&sex=' + this.data.list1[this.data.index1] + '&jslb=' + this.data.list[this.data.index]+
					'&workYear='+this.data.workYear+'&prov='+this.data.region[0]+'&city='+this.data.region[1]+'&county='+this.data.region[2],
					success: (e) => {
						console.log(e)
						wx.navigateBack({
							delta:1
						})
					}
			})
		} else {
			wx.showToast({
				icon: 'none',
				title: '请正确填写信息'
			})
		}

	}
})
